import {
  defineComponent,
  inject,
  computed,
  openBlock,
  createElementBlock,
  Fragment,
  renderList,
  createBlock,
  resolveDynamicComponent,
  normalizeStyle,
  unref,
  normalizeClass,
  withCtx,
  createCommentVNode
} from "vue";
import {
  u as useCanvasState,
  g as getComponentStyle,
  S as Shape,
  a as getInnerComponentShapeStyle,
  e as eventBus,
  f as filterStyle,
  c as channels,
  _ as _export_sfc
} from "./index-CEDaTd93.js";
const _hoisted_1 = {
  key: 0,
  class: "group"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "Group",
  props: {
    component: {}
  },
  setup(__props) {
    const props = __props;
    const dataChange = (resp, _) => {
      if (resp.status === "SUCCESS") {
        const data = resp.afterData;
        const propValue = props.component.propValue;
        const myChannel = propValue.dataOption.channel;
        const channel = myChannel ? myChannel : props.component.id;
        if (propValue.isRegExp) {
          const keys = Object.keys(channels);
          const matchReg = new RegExp(channel);
          keys.forEach(el => {
            if (matchReg.test(el)) {
              eventBus.on(el, data);
            }
          });
        } else {
          eventBus.on(channel, data);
        }
      }
    };
    const { useData } = inject("HOOKS") || {};
    if (useData) {
      useData(props.component, dataChange);
    }
    const canvasState = useCanvasState();
    const editMode = computed(() => canvasState.isEditMode);
    const curComponent = computed(() => canvasState.curComponent);
    const isActive = computed(() => {
      var _a;
      let curComponent2 = canvasState.curComponent;
      while (curComponent2) {
        if (
          ((_a = curComponent2.parent) == null ? void 0 : _a.id) ===
          props.component.id
        ) {
          return true;
        }
        curComponent2 = curComponent2.parent;
      }
      return false;
    });
    const isShow = display => {
      return !(canvasState.isEditMode && !display);
    };
    const getShapeStyle = item => {
      var _a;
      if ((_a = item.groupStyle) == null ? void 0 : _a.gheight) {
        return filterStyle(item.groupStyle, [
          "gtop",
          "gleft",
          "gwidth",
          "gheight",
          "grotate"
        ]);
      } else {
        return filterStyle(item.style, [
          "top",
          "left",
          "width",
          "height",
          "rotate"
        ]);
      }
    };
    return (_ctx, _cache) => {
      return !editMode.value
        ? (openBlock(),
          createElementBlock("div", _hoisted_1, [
            (openBlock(true),
            createElementBlock(
              Fragment,
              null,
              renderList(_ctx.component.subComponents || [], item => {
                return (
                  openBlock(),
                  createBlock(
                    resolveDynamicComponent(item.component),
                    {
                      key: item.id,
                      id: "component" + item.id,
                      class: "component",
                      style: normalizeStyle(unref(getComponentStyle)(item)),
                      component: item
                    },
                    null,
                    8,
                    ["id", "style", "component"]
                  )
                );
              }),
              128
            ))
          ]))
        : (openBlock(),
          createElementBlock(
            "div",
            {
              key: 1,
              class: normalizeClass(["group", { dotted: isActive.value }])
            },
            [
              (openBlock(true),
              createElementBlock(
                Fragment,
                null,
                renderList(_ctx.component.subComponents || [], (item, i) => {
                  return (
                    openBlock(),
                    createElementBlock(
                      Fragment,
                      {
                        key: item.id
                      },
                      [
                        isShow(item.display)
                          ? (openBlock(),
                            createBlock(
                              unref(Shape),
                              {
                                key: 0,
                                id: "shape" + item.id,
                                defaultStyle: item.style,
                                style: normalizeStyle(getShapeStyle(item)),
                                active:
                                  item.id === (curComponent.value || {}).id,
                                info: item,
                                class: normalizeClass({ lock: item.locked }),
                                isInner: true,
                                index: i
                              },
                              {
                                default: withCtx(() => [
                                  (openBlock(),
                                  createBlock(
                                    resolveDynamicComponent(item.component),
                                    {
                                      id: "component" + item.id,
                                      class: "component",
                                      style: normalizeStyle(
                                        unref(getInnerComponentShapeStyle)(item)
                                      ),
                                      component: item
                                    },
                                    null,
                                    8,
                                    ["id", "style", "component"]
                                  ))
                                ]),
                                _: 2
                              },
                              1032,
                              [
                                "id",
                                "defaultStyle",
                                "style",
                                "active",
                                "info",
                                "class",
                                "index"
                              ]
                            ))
                          : createCommentVNode("", true)
                      ],
                      64
                    )
                  );
                }),
                128
              ))
            ],
            2
          ));
    };
  }
});
const Group = /* @__PURE__ */ _export_sfc(_sfc_main, [
  ["__scopeId", "data-v-921700d1"]
]);
export { Group as default };
